﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Alserve.Ffl.Data;

public partial class ffl_anonymous_topplayers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            PopulatePositionRepeater();
    }

    private void PopulatePositionRepeater()
    {
        Position thisPosition = new Position();
        thisPosition.LoadAll();
        PositionRepeater.DataSource = thisPosition.DefaultView;
        PositionRepeater.DataBind();
    }

    protected void PositionRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater playerPositionRepeater = (Repeater)e.Item.FindControl("PlayerPositionRepeater");
            HiddenField positionHidden = (HiddenField)e.Item.FindControl("PositionIdHidden");
            Int32 positionId = Convert.ToInt32(positionHidden.Value);

            _PlayerView thisPlayerView = new _PlayerView();
            thisPlayerView.Where.PositionId.Value = positionId;
            thisPlayerView.Query.AddOrderBy(_PlayerView.ColumnNames.TotalPoints, MyGeneration.dOOdads.WhereParameter.Dir.DESC);
            thisPlayerView.Query.AddOrderBy(_PlayerView.ColumnNames.Surname, MyGeneration.dOOdads.WhereParameter.Dir.ASC);
            thisPlayerView.Query.Top = 3;

            if (thisPlayerView.Query.Load())
            {
                playerPositionRepeater.DataSource = thisPlayerView.DefaultView;
                playerPositionRepeater.DataBind();
            }
        }
    }

}
